package com.rran.study.designpattern.behavioral.observer.service;

import com.google.common.collect.Lists;
import com.rran.study.designpattern.behavioral.observer.event.PlaceOrderEvent;

import java.util.List;

/**
 * @author yy
 * @Type PlaceOrderTriggerSource.java
 * @Desc
 * @date 2020/7/21 17:49
 */
public class PlaceOrderTriggerSource implements TriggerSource{

    private List<PlaceOrderObserver> observerList = Lists.newArrayList();//被观察者列表

    @Override
    public void startUpObserver(PlaceOrderEvent event) {
        for(PlaceOrderObserver observer : observerList){
            observer.actionPlaceOrder(event);//循环执行各个观察者方法
        }
    }

    @Override
    public void registObserver(PlaceOrderObserver observer) {
        observerList.add(observer);//添加到观察者容器中
    }
}
